$(function() {
	admin.orderBase.init();
});
Namespace('admin.orderBase', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
				var row = $('#datagrid').datagrid('getSelected');
				admin.orderBase.detail(row.id);
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	detail:function(id) {
		if (id != null) {
			top.addTab(id,'订单详情', contextPath+'/order/base/detail?id=' + id);
		}
	},
	export2Excel : function() {//导出excel
		var url = contextPath + '/order/base/export2Excel';
		var communityId = $('#communityId').val();
		var orderNo = $('#orderNo').val();
		var buyerNick = $('#buyerNick').val();
		var shopName = $('#shopName').val();
		var orderType = $('#orderType').val();
		var orderStatus = $('#orderStatus').val();
		var payStatus = $('#payStatus').val();
		var deliveryStatus = $('#deliveryStatus').val();//收发货状态
		var isExternal = $('#isExternal').val();
		var endAtStr = $("input[name=endAtStr]").val();//$('#endAtStr').val();
		var startAtStr = $("input[name=startAtStr]").val();//$('#startAtStr').val();
		var params ={};
		var paramstr ="";

		if(communityId!='' && communityId!=null){
			paramstr+="&communityId="+communityId;
		}
		if(orderNo!='' && orderNo!=null){
			paramstr+="&orderNo="+orderNo;
		}
		if(buyerNick!='' && buyerNick!=null){
			paramstr+="&buyerNick="+buyerNick;
		}
		if(shopName!='' && shopName!=null){
			paramstr+="&shopName="+shopName;
		}
		if(orderType!='' && orderType!=null){
			paramstr+="&orderType="+orderType;
		}
		if(orderStatus!='' && orderStatus!=null){
			paramstr+="&orderStatus="+orderStatus;
		}
		if(payStatus!='' && payStatus!=null){
			paramstr+="&payStatus="+payStatus;
		}
		if(deliveryStatus!='' && deliveryStatus!=null){
			paramstr+="&deliveryStatus="+deliveryStatus;
		}
		if(isExternal!='' && isExternal!=null){
			paramstr+="&isExternal="+isExternal;
		}
		if(startAtStr!='' && startAtStr!=null){
			paramstr+="&startAtStr="+startAtStr;
		}
		if(endAtStr!='' && endAtStr!=null){
			paramstr+="&endAtStr="+endAtStr;
		}
		if(paramstr!=''){
			url += "?"+paramstr;
		}
		window.open(url,"");
	},
	cancel:function(id) {
		if (id != null) {
			$.messager.confirm('提示信息', '确定取消订单吗?', function(sure) {
				if (!sure) return;
				$.postJson(contextPath+'/order/base/adminCancel',{id:id},function(result) {
					if(result.code==1) {
						top.showInfo('订单取消成功!');
						$('#datagrid').datagrid('reload');
					} else {
						top.showInfo('订单取消失败：'+result.msg);
					}
				});
			});
		}
	},
	agreeReturnPay:function(id) {
		if (id != null) {
			$.messager.confirm('提示信息', '确定同意订单退款吗?', function(sure) {
				if (!sure) return;
				$.postJson(contextPath+'/order/base/adminAgreeReturnPay',{id:id},function(result) {
					if(result.code==1) {
						top.showInfo('订单退款成功!');
						$('#datagrid').datagrid('reload');
					} else {
						top.showInfo('订单取消失败：'+result.msg);
					}
				});
			});
		}
	},
	refuseReturnPay:function(id) {
		if (id != null) {
			$.messager.confirm('提示信息', '确定拒绝订单退款吗?', function(sure) {
				if (!sure) return;
				$.postJson(contextPath+'/order/base/adminRefuseReturnPay',{id:id},function(result) {
					if(result.code==1) {
						top.showInfo('已拒绝订单退款!');
						$('#datagrid').datagrid('reload');
					} else {
						top.showInfo('操作失败：'+result.msg);
					}
				});
			});
		}
	}
});